package com.example.minzhengtong.ui.add

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.ImageView
import com.example.minzhengtong.Const
import com.example.minzhengtong.R
import com.example.minzhengtong.base.BaseA
import com.example.minzhengtong.data.BannerBean
import com.example.minzhengtong.databinding.ActivityMedicalInsuranceBinding
import com.example.minzhengtong.ui.GJJServiceA
import com.example.minzhengtong.ui.adapter.AdapterThirdBanner
import com.youth.banner.listener.OnPageChangeListener
import kotlinx.android.synthetic.main.activity_medical_insurance.view.*

/**
 * created by WY on 2021/6/17.
 * 医保查询
 */
class MedicalInsuranceA : BaseA(){

    companion object{
        fun enterThis(context: Context){
            val intent = Intent(context, MedicalInsuranceA::class.java)
            context.startActivity(intent)
        }
    }

    private lateinit var binding : ActivityMedicalInsuranceBinding
    private val mBanner = mutableListOf<BannerBean>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMedicalInsuranceBinding.inflate(layoutInflater)
        overridePendingTransition(0,0)
        setContentView(binding.root)
        initView()
    }

    private fun initView(){
        initImmerBar(true, R.id.title_bar)
        setToolBarVisiabale(false)

        val inflater = LayoutInflater.from(baseContext)

        mBanner.add(BannerBean(logo = R.mipmap.yilbanner1,title = ""))
        mBanner.add(BannerBean(logo = R.mipmap.yilbanner2,title = ""))

        binding.info.setOnClickListener {
            EnterInfoSearchA.enterThis(baseContext)
        }

        binding.webview.loadUrl("${Const.waterMark}福建医保")

        binding.banner.apply {
            adapter = AdapterThirdBanner(mBanner)
//            for (i in mBanner.indices){
//                val normalDot = inflater.inflate(R.layout.third_dot,binding.indicatorContainer,false) as ImageView
//                normalDot.setImageResource(if (i == currentItem) R.drawable.gren_oval else R.drawable.white_oval)
//                binding.indicatorContainer.addView(normalDot)
//            }
            addOnPageChangeListener(object : OnPageChangeListener {
                override fun onPageScrolled(
                    position: Int,
                    positionOffset: Float,
                    positionOffsetPixels: Int
                ) {

                }

                override fun onPageSelected(position: Int) {
//                    for (i in mBanner.indices){
//                        val initDot = binding.indicatorContainer.getChildAt(i) as ImageView
//                        initDot.setImageResource(R.drawable.dot_normal)
//                    }
//                    val selectDot = binding.indicatorContainer.getChildAt(position) as ImageView
//                    selectDot.setImageResource(R.drawable.dot_select)
                }

                override fun onPageScrollStateChanged(state: Int) {

                }
            })
        }

    }

    override fun finish() {
        super.finish()
        overridePendingTransition(0,0)
    }

}